# 导包
import unittest
from api.staff import StaffAPI
import requests
import app
from lib.dbutil import DBUtil


# 创建测试类
class TestStaffAPI(unittest.TestCase):
    # 类前置处理
    @classmethod
    def setUpClass(cls) -> None:
        sql = "delete from bs_user where mobile='{}'".format(app.INSERT_DATA.get("mobile"))
        print(sql)
        # 清理测试数据
        print(DBUtil.exe_sql("delete from bs_user where mobile='{}'".format(app.INSERT_DATA.get("mobile"))))
        # print(DBUtil.exe_sql("delete from bs_user where mobile='13899976501'"))

    # 前置处理
    def setUp(self) -> None:
        # 实例化接口类
        self.staff_api = StaffAPI()
        # 创建session对象
        self.session = requests.session()

    # 后置处理
    def tearDown(self) -> None:
        self.session.close()

    # 类后置处理
    @classmethod
    def tearDownClass(cls) -> None:
        # 清理测试数据
        print(DBUtil.exe_sql("delete from bs_user where mobile='{}'".format(app.INSERT_DATA.get("mobile"))))

        # 清理测试数据
        # print(DBUtil.exe_sql("delete from bs_user where mobile='13899976501'"))

    # 登录成功
    def test_login(self):
        response = self.staff_api.insert_staff(self.session, app.INSERT_DATA, app.headers_data)
        print(response.json())
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
